/*j07c8riwYnz20MYibuDbtJvPGYQwyxUjsKp1kroOzVJiPy2vSbZROeEo1fJgmiQR*/
/*
 * @Author: xiahui 
 * @PageInfo: 卡片态翻页 
 * @Date: 2019-01-14 14:26:32 
 * @Last Modified by: zhr
 * @Last Modified time: 2019-12-11 14:00:13
 */
import { ajax } from 'nc-lightapp-front';
import { PAGECODE, URL, DATASOURCECACHE, FIELDS, AREA } from '../../constance';
import { getCacheDataByPk } from '../../../../../scmpub/scmpub/pub/cache';
import { showRefreshInfo } from '../../../../../scmpub/scmpub/pub/tool/messageUtil';
import { setEmptyValueDisplay, showSagaErrorToasts } from '../viewControl/buttonControl';
import { setCardPage, setCardCacheData, addRowForModify } from '../../utils/cardPageUtil';

export default function(props, pk, isRefresh = false, cancel = false) {
	// 考虑删除页时，下一页为null的情况
	if (!pk) {
		debugger;
		setEmptyValueDisplay(props);
		return;
	}

	// 刷新需要重新查询数据
	if (!isRefresh) {
		debugger;
		let cacheData = getCacheDataByPk(props, DATASOURCECACHE.dataSourceListCacheKey, pk); // 获取缓存数据
		if (cacheData) {
			setCardPage.call(this, props, cacheData, false);
			//跳转卡片弹出提示框
			showSagaErrorToasts(this.props, AREA.cardFormId, FIELDS.pk_ct_pu);
			return;
		}
	}

	let reqData = {
		pks: [ pk ],
		pagecode: PAGECODE.cardPagecode
	};

	let scene = props.getUrlParam('scene');
	if (scene && !isRefresh) {
		// 报账平台，点击历史版本时，显示最新版本
		reqData['userObj'] = { scene };
	}
	//分摊明细保存后重新查询 xugao 2022-10-31 09:48:00
	ajax({
		url: URL.queryCard,
		data: reqData,
		success: (res) => {
			if (res.formulamsg && res.formulamsg instanceof Array && res.formulamsg.length > 0) {
				props.dealFormulamsg(
					res.formulamsg //参数一：返回的公式对象
				);
			}
			if (res.success && res.data) {
				props.setUrlParam({ id: pk });
				setCardPage.call(this, props, res.data, false);
				setCardCacheData.call(this, props, res.data);
				if (!cancel) {
					isRefresh ? showRefreshInfo() : '';
				}
				addRowForModify.call(this, props);
				//跳转卡片弹出提示框
				showSagaErrorToasts(this.props, AREA.cardFormId, FIELDS.pk_ct_pu);
			} else {
				setEmptyValueDisplay(props);
			}
		}
	});
}

/*j07c8riwYnz20MYibuDbtJvPGYQwyxUjsKp1kroOzVJiPy2vSbZROeEo1fJgmiQR*/